type Key = 'todoList' | 'labels' | 'customConfig' | 'filterOptions'

const PREFIX = 'cogni_todo_'

export const setStorageSync = <T>(key: Key, value: T) => {
  try {
    uni.setStorageSync(PREFIX + key, JSON.stringify(value))
    return true
  } catch (error) {
    console.error('Error setting storage for key', key, ':', error)
    return false
  }
}

export const getStorageSync = <T>(key: Key): T | null => {
  try {
    const data = uni.getStorageSync(PREFIX + key)
    return data ? JSON.parse(data) : null
  } catch (error) {
    console.error('Error getting storage for key', key, ':', error)
    return null
  }
}
